<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ include file="../../base.jsp" %>
<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据 - AdminLTE2定制版</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 页面meta /-->
    <script src="${ctx}/plugins/jQuery/jquery-2.2.3.min.js"></script>
</head>
<script>
    function deleteById() {
        var id = getCheckId()
        if (id) {
            if (confirm("你确认要删除此条记录吗？")) {
                location.href = "${ctx}/cargo/product/delete.do?id=" + id;
            }
        } else {
            alert("请勾选待处理的记录，且每次只能勾选一个")
        }
    }


    function modifyById() {
        var id = getCheckId();
        if (id) {
            location.href = "${ctx}/cargo/product/toUpdate.do?id=" + id;
        } else {
            alert("请勾选待处理的记录，且每次只能勾选一个")
        }
    }


</script>
<body>
<div id="frameContent" class="content-wrapper" style="margin-left:0px;">
    <section class="content-header">
        <h1>
            基础信息
            <small>产品信息</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>
        </ol>
    </section>
    <!-- 内容头部 /-->

    <!-- 正文区域 -->
    <section class="content">

        <!-- .box-body -->
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">产品信息列表</h3>
            </div>

            <div class="box-body">

                <!-- 数据表格 -->
                <div class="table-box">

                    <!--工具栏-->
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default" title="新建"
                                        onclick='location.href="${ctx}/cargo/product/toAdd.do?id="+$("#factoryInfo").val()+""'>
                                    <i
                                            class="fa fa-file-o"></i> 新建
                                </button>
                                <button type="button" class="btn btn-default" title="删除" onclick='deleteById()'><i
                                        class="fa fa-trash-o"></i> 删除
                                </button>
                                <button type="button" class="btn btn-default" title="修改" onclick='modifyById()'><i
                                        class="fa fa-edit"></i> 修改
                                </button>
                                <button type="button" class="btn btn-default" title="刷新"
                                        onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="box-tools pull-right">
                        <div class="has-feedback">
                            <%--<input type="text" class="form-control input-sm" placeholder="搜索">--%>
                            <select style="width: 200px" class="form-control input-sm" name="factoryId" id="factoryInfo"
                                    onchange="document.getElementById('factoryName').value=this.options[this.selectedIndex].text">
                                <option value="">全部</option>
                                <c:forEach items="${factoryList}" var="factory">
                                    <option value="${factory.id}" ${factory.id == id ?'selected':''}>${factory.factoryName}</option>
                                </c:forEach>
                            </select>
                            <%--<span class="glyphicon glyphicon-check form-control-feedback"></span>--%>
                        </div>
                    </div>
                    <!--工具栏/-->

                    <!--数据列表-->
                    <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                        <thead>
                        <tr>
                            <th class="" style="padding-right:0px;">

                            </th>
                            <th class="sorting">编号</th>
                            <th class="sorting">类型</th>
                            <th class="sorting">厂家</th>
                            <th class="sorting">参考价</th>
                            <th class="sorting">说明</th>
                            <th class="sorting">备注</th>
                            <%--<th class="sorting">传真</th>--%>
                            <th class="sorting">产地</th>
                            <th class="sorting">验货员</th>
                            <th class="sorting">状态</th>
                        </tr>
                        </thead>
                        <tbody id="first">
                        <c:forEach items="${page.list}" var="o">
                            <tr>
                                <td><input type='checkbox' name='id' value='${o.id}'/></td>
                                <td>${o.productNo}</td>
                                <td>${factory.ctype}</td>
                                <td>${o.factoryName}</td>
                                <td>${o.price}</td>
                                <td>${o.description}</td>
                                <td>${o.remark}</td>
                                <td>${factory.address}</td>
                                <td>${factory.inspector}</td>
                                <td><c:if test='${factory.state==0}'>停产</c:if><c:if test='${factory.state==1}'><font
                                        color='green'>正常</font></c:if></td>
                            </tr>
                        </c:forEach>
                        </tbody>
                        <!--
                    <tfoot>
                    <tr>
                    <th>Rendering engine</th>
                    <th>Browser</th>
                    <th>Platform(s)</th>
                    <th>Engine version</th>
                    <th>CSS grade</th>
                    </tr>
                    </tfoot>-->
                    </table>
                    <!--数据列表/-->

                    <!--工具栏/-->

                </div>
                <!-- 数据表格 /-->


            </div>
            <!-- /.box-body -->

            <!-- .box-footer-->
            <div class="box-footer">
                <jsp:include page="../../common/page.jsp">
                    <jsp:param value="${ctx}/cargo/contract/list.do" name="pageUrl"/>
                </jsp:include>
            </div>
            <!-- /.box-footer-->


        </div>

    </section>
</div>
<script>
    var id = "${id}";
    var factoryInfo = document.getElementById("factoryInfo");
    factoryInfo.onchange = ajax;
    factoryInfo.focus = ajax;

    function ajax() {
        // alert(factoryInfo.value)
        id = factoryInfo.value;
        if (id==="") {
            location.href = "${pageContext.request.contextPath}/cargo/product/list.do?";
        } else {
            location.href = "${pageContext.request.contextPath}/cargo/product/list.do?id=" + id;
        }
    }

    // nav+="<tr><td><input type='checkbox' name='id' value='"+o.id+"'/></td><td>"+o.productNo+"</td><td>${factory.ctype}</td><td>"+o.factoryName+"</td><td>"+o.price+"</td><td>"+o.description+"</td><td>"+o.remark+"</td><td>${factory.address}</td><td>${factory.inspector}</td><td><c:if test='${factory.state==0}'>停产</c:if><c:if test='${factory.state==1}'><font color='green'>正常</font></c:if></td></tr>"

</script>
</body>

</html>


<%--
<script>
    var factoryInfo = document.getElementById("factoryInfo");
    factoryInfo.onchange = ajax;
    factoryInfo.focus = ajax;

    function ajax() {
        // alert(factoryInfo.value)
        var id = factoryInfo.value;
        if (id != "") {
            $.ajax({
                url: "${pageContext.request.contextPath}/cargo/product/listByFactory.do?id=" + id,
                dataTape: "json",
                success: function (data) {
                    var nav = "";
                    $("#first").after(nav);
                    for (let o of data) {
                        nav += "<tr><td><input type='checkbox' name='id' value='" + o.id + "'/></td><td>" + o.productNo + "</td><td>${factory.ctype}</td><td>" + o.factoryName + "</td><td>" + o.price + "</td><td>" + o.description + "</td><td>" + o.remark + "</td><td>${factory.address}</td><td>${factory.inspector}</td><td><c:if test='${factory.state==0}'>停产</c:if><c:if test='${factory.state==1}'><font color='green'>正常</font></c:if></td></tr>"
                    }
                    $("#first").html(nav);
                }
            })
        }else {
            location.reload();
        }
    }

    // nav+="<tr><td><input type='checkbox' name='id' value='"+o.id+"'/></td><td>"+o.productNo+"</td><td>${factory.ctype}</td><td>"+o.factoryName+"</td><td>"+o.price+"</td><td>"+o.description+"</td><td>"+o.remark+"</td><td>${factory.address}</td><td>${factory.inspector}</td><td><c:if test='${factory.state==0}'>停产</c:if><c:if test='${factory.state==1}'><font color='green'>正常</font></c:if></td></tr>"

</script> --%>
